package game.roles.bullets;

import game.roles.Role;
import game.utils.ImageChange;

import java.awt.*;

/**
 * @author liuyulai
 * Created with IntelliJ IDEA.
 * Date: 21.5.8
 * Time: 10:39
 * Description: 星星子弹
 */
public class StarBullet extends Role implements EnemyBullet {
    /**
     * boss子弹图片
     */
    public static Image[] starImages;

    /**
     * 图片切换
     */
    private ImageChange imageChange = new ImageChange(3);

    /**
     * 左上方向
     */
    public static final int LEFT_UP = 0;

    /**
     * 左下方向
     */
    public static final int LEFT_DOWN = 1;

    /**
     * 直线
     */
    public static final int FRONT = 3;

    /**
     * 方向初始化
     */
    private int direction;

    private boolean jumpDown = false;

    private boolean jumpUp = false;


    public StarBullet(int x, int y, int direction) {
        super(x, y, 60, 60);
        this.direction = direction;
    }

    @Override
    public void rolesMove() {
        this.img = imageChange.change(starImages);

        //具有弹射效果
        if (this.direction == LEFT_UP && !jumpDown) {
            this.x -= 6;
            this.y -= 6;
            if (this.y <= 0) {
                jumpDown = true;
            }
        } else if (this.direction == LEFT_DOWN && !jumpUp) {
            this.x -= 6;
            this.y += 6;
            if (this.y >= 600) {
                jumpUp = true;
            }
        } else if (this.direction == LEFT_UP && jumpDown) {
            this.x -= 6;
            this.y += 6;
            if (this.y >= 600) {
                jumpDown = false;
            }
        } else if (this.direction == LEFT_DOWN && jumpUp) {
            this.x -= 6;
            this.y -= 6;
            if (this.y <= 0) {
                jumpUp = false;
            }
        } else if (this.direction == FRONT) {
            this.x -= 4;
        }
    }
}
